<h2>{{ text_write }}</h2>
{% if review_guest %}
	<div class="form-group required">
		<div class="col-sm-12">
			<label class="control-label" for="input-name">{{ entry_name }}</label>
			<input type="text" name="name" value="{{ customer_name }}" id="input-name" class="form-control" />
		</div>
	</div>
	<div class="form-group required">
		<div class="col-sm-12">
			<label class="control-label" for="input-review">{{ entry_review }}</label>
			<textarea name="text" rows="5" id="input-review" class="form-control"></textarea>
			<div class="help-block">{{ text_note }}</div>
		</div>
	</div>
	<div class="form-group required">
		<div class="col-sm-12">
			<label class="control-label mr-1">{{ entry_rating }}</label>
			{{ entry_bad }}
			{% for radio in 1..5 %}
				<input type="radio" name="rating" value="{{ loop.index }}" />
			{% endfor %}
			{{ entry_good }}
		</div>
	</div>
	{{ captcha }}
	<button type="button" id="button-review" data-loading-text="{{ text_loading }}" class="btn btn-primary">{{ button_submit }}</button>
{% else %}
	{{ text_login }}
{% endif %}

<script type="text/javascript">
    jQuery(document).ready(function($) {
        $('#review').load('index.php?route=product/product/review&product_id={{ product_id }}');

        $('#button-review').on('click', function() {
            $.ajax({
                url: 'index.php?route=product/product/write&product_id={{ product_id }}',
                type: 'post',
                dataType: 'json',
                data: $("#form-review").serialize(),
                success: function(json) {
                    $('.alert-dismissible').remove();

                    if (json['error']) {
                        layer.msg(json['error']);
                    }

                    if (json['success']) {
                        layer.msg(json['success']);

                        $('input[name=\'name\'], textarea[name=\'text\']').val('');
                        $('input[name=\'rating\']:checked').prop('checked', false);
                    }
                }
            });
        });
    });
</script>